package data.xml.parser;

import java.io.InputStream;


import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
/**
 * 
 * @author Miky
 * @version $Id: XmlUtil.java 22 2013-04-05 18:48:33Z mikael.beyene $
 */
public final class XmlUtil {

	private XmlUtil() {
	}

	public static boolean validateXmlAgainstScheme(InputStream xml, InputStream xsd) {
		try {
			SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
			Schema schema = factory.newSchema(new StreamSource(xsd));
			Validator validator = schema.newValidator();
			validator.validate(new StreamSource(xml));
			return true;
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
			return false;
		}
	}

}